﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace DARE
{
    /// <summary>
    /// represents the movement of the mouse with the last position, the current position, the movement...
    /// </summary>
    public class CMouseMoveEvent
    {
        #region fields

        private Vector2 m_lastPosition;
        private Vector2 m_currentPosition;
        private Vector2 m_movement;
        private bool m_isCentered;

        #endregion

        #region properties

        public Vector2 LastPosition { get { return m_lastPosition - m_movement; } }
        public Vector2 Movement { get { return m_movement; } }
        public Vector2 CurrentPosition { get { return m_currentPosition; } set { m_currentPosition = value; } }

        /// <summary>
        /// gets/sets the centered boolean. If the mouse is centered, the position stays always at the center of the screen but you will be able to get the movement.
        /// </summary>
        internal bool IsCentered
        {
            get { return m_isCentered; }
            set
            {
                m_isCentered = value;
                if (value == true)
                {
                    m_lastPosition = m_currentPosition = new Vector2(CDare.Instance.GraphicsDevice.Viewport.Width / 2, CDare.Instance.GraphicsDevice.Viewport.Height / 2);
                    m_movement = Vector2.Zero;
                    Mouse.SetPosition((int)(CDare.Instance.GraphicsDevice.Viewport.Width / 2.0f), (int)(CDare.Instance.GraphicsDevice.Viewport.Height / 2.0f));
                }
            }
        }

        #endregion

        #region methods

        public void Test()
        {
            m_movement = Vector2.Zero;
            m_currentPosition = m_lastPosition = new Vector2(CDare.Instance.GraphicsDevice.Viewport.Width / 2, CDare.Instance.GraphicsDevice.Viewport.Height / 2);
        }

        public void Clear()
        {
            m_movement = Vector2.Zero;
            Reset();
        }

        public void Reset()
        {
            m_movement = m_currentPosition - m_lastPosition;
            if (m_isCentered)
                m_lastPosition = new Vector2(CDare.Instance.GraphicsDevice.Viewport.Width / 2, CDare.Instance.GraphicsDevice.Viewport.Height / 2);
            else
                m_lastPosition = m_currentPosition;
        }

        #endregion

    }
}
